import type { DirectiveBinding } from "vue"
//商品图片hover效果
export const hover = (el: HTMLElement, binding: DirectiveBinding) => {
    if (binding.arg === 'img') {
        if (binding.modifiers.over) {
            el.addEventListener('mouseover', (e: any) => {
                if (e.target.nodeName !== "IMG") return;
                e.target.src = binding.value.scenePicUrl;
            })
        }
        if (binding.modifiers.out) {
            el.addEventListener('mouseout', (e: any) => {
                if (e.target.nodeName !== "IMG") return;
                e.target.src = binding.value.listPicUrl;
            })
        }
    }
}
//路由跳转到详情页
export const toDetail = (el: HTMLElement, binding: DirectiveBinding) => {
    el.addEventListener('click', (e: any) => {
        if (e.target.nodeName !== "IMG" && e.target.nodeName !== "A") return;
        binding.value.push({
            name: "WDetail",
            query: {
                id: e.target.dataset.id,
            },
        });
    })
}